package com.pricl.frame.core.web;

import org.springframework.core.MethodParameter;
import org.springframework.web.bind.support.WebDataBinderFactory;
import org.springframework.web.context.request.NativeWebRequest;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.method.support.ModelAndViewContainer;

import com.pricl.frame.core.User;

/**
 * 
 * @author cheng(iknoweth@yahoo.com)
 * @date 2016-5-4 下午10:17:47
 */
public class ArgumentResolver implements HandlerMethodArgumentResolver {

	@Override
	public boolean supportsParameter(MethodParameter parameter) {
		return User.class.isAssignableFrom(parameter.getParameterType());
	}

	@Override
	public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer,
			NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception {
//		String sid = webRequest.getNativeRequest(HttpServletRequest.class).getSession().getId();
//		User user = Helper.getUser(sid);
		User user= Helper.getCurrentUser();
		
		return user;
	}
}
